package be.bonamis.umpire.utils;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import be.bonamis.umpire.domain.LeagueDay;
import be.bonamis.umpire.domain.Umpire;
import be.bonamis.umpire.old.domain.CsvDispoArbitres;
import be.bonamis.umpire.old.domain.CsvDispoJournees;

import com.google.common.base.Function;

public interface Mappings {

	static final Logger LOGGER = LoggerFactory.getLogger(Mappings.class);

	interface Umpires {
		Function<CsvDispoArbitres, Umpire> fromOldDbtoNew = new Function<CsvDispoArbitres, Umpire>() {
			public Umpire apply(CsvDispoArbitres arbitre) {
				Umpire umpire = new Umpire();
				umpire.setDispoName(arbitre.getNomArbitre());
				umpire.setLogin(arbitre.getLogin());
				umpire.setPassword(arbitre.getPasswd());
				umpire.setOldId(arbitre.getId());
				return umpire;
			}
		};
	};

	interface LeagueDays {
		Function<CsvDispoJournees, LeagueDay> fromOldDbtoNew = new Function<CsvDispoJournees, LeagueDay>() {
			public LeagueDay apply(CsvDispoJournees journee) {
				LeagueDay ld = new LeagueDay();
				if (journee.getBlocage() == 1) {
					ld.setBlocked(true);
				} else {
					ld.setBlocked(false);
				}
				DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
				ld.setDay(fmt.parseDateTime(journee.getDateJourn()));
				ld.setOldId(journee.getIdJourn());
				return ld;
			}
		};
	}
}
